package com.web.music.portal.mvc;

import java.beans.PropertyEditorSupport;
import com.web.music.model.Artist;
import com.web.music.interfaces.ArtistService;

public class ArtistPropertyEditor extends PropertyEditorSupport {
	
	private ArtistService artistService;
	
	public ArtistPropertyEditor(ArtistService artistService) {
		this.artistService = artistService;
	}

	@Override
	public String getAsText() {
		if (getValue() != null && getValue() instanceof Artist) {
			Artist artist = (Artist) getValue();
			return artist.getName();
		}
		return super.getAsText();
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		setValue(artistService.getById(new Long(text)));
	}

	
}